package com.baolai.controller;

import com.alibaba.fastjson.JSONObject;
import com.baolai.result.Result;
import com.baolai.result.ResultUtil;
import com.baolai.service.GoodsRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "入库出库记录")
@ResponseBody
@RestController
@RequestMapping("/goods-record")
public class GoodsRecordController {

    @Autowired
    GoodsRecordService goodsRecordService;

    @ApiOperation(value = "添加记录")
    @PostMapping("add")
    public Result addGoodsRecord(@RequestBody JSONObject jsonObject){
        if(goodsRecordService.addGoodsRecord(jsonObject.getString("type"),jsonObject.getString("goodsId"),
                jsonObject.getString("site"),jsonObject.getInteger("number"),jsonObject.getString("account"),
                jsonObject.getString("name"))){
            return ResultUtil.success("记录成功");
        }
        return ResultUtil.error("记录失败");
    }

    @ApiOperation(value = "分页查询全部记录")
    @PostMapping("list")
    public Result listGoodsRecord(@RequestBody JSONObject jsonObject){
        return ResultUtil.success(goodsRecordService.listGoodsRecord(jsonObject.getInteger("current"),jsonObject.getInteger("size")));
    }

    @ApiOperation(value = "根据日期分页查询记录")
    @PostMapping("query")
    public Result queryGoodsRecord(@RequestBody JSONObject jsonObject){
        return ResultUtil.success(goodsRecordService.queryGoodsRecord(jsonObject.getString("begin"),jsonObject.getString("end"),
                jsonObject.getInteger("current"),jsonObject.getInteger("size")));
    }

    @ApiOperation(value = "根据日期和某个备件编码分页查询记录")
    @PostMapping("queryByGoodsId")
    public Result queryGoodsRecordByGoodsId(@RequestBody JSONObject jsonObject){
        return ResultUtil.success(goodsRecordService.queryGoodsRecordByGoodsId(jsonObject.getString("goodsId"),
                jsonObject.getString("begin"),jsonObject.getString("end"),
                jsonObject.getInteger("current"),jsonObject.getInteger("size")));
    }
}
